using System;
using System.Collections.Generic;
using System.Text;
using Decav.Reality;
using System.Net.Mail;

namespace Decav.Gatsb.Mobile
{
    /// <summary>
    /// A message that originates from a mobile telephone, such as an
    /// SMS or MMS message.
    /// </summary>
    [Serializable]
    public abstract class MobileMessage 
    {
        public MobileMessage(EmailAddress receivingAddress, EmailAddress sendingAddress, PhoneNumber sendingTel, DateTime postTime, string body)
        {
            if (sendingAddress == null)
                throw new ArgumentNullException("sendingAddress");

            if (receivingAddress == null)
                throw new ArgumentNullException("receivingAddress");

            // Get all the parts of a string so we can split on the first elipse
            // This is so that commands on the first line are considered split by an elipse
            /*int indexOfElipse = body.IndexOf("...");
            if (indexOfElipse < body.IndexOf("\r\n") && indexOfElipse != -1 && indexOfElipse < 100)
            {
                string[] parts = body.Split(new string[] { "..." }, 2, StringSplitOptions.None);
                body = string.Join("\r\n", parts);
            }*/

            _body = body;
            _sendingTel = sendingTel;
            _postTime = postTime;
            _recipientAddress = receivingAddress;
            _sendingAddress = sendingAddress;
        }

        private EmailAddress _recipientAddress;
        private EmailAddress _sendingAddress;
        private string _body;
        private PhoneNumber _sendingTel;
        private DateTime _postTime;

        /// <summary>
        /// Gets the email address that is receiving the message.
        /// </summary>
        public EmailAddress RecipientAddress
        {
            get
            {
                return _recipientAddress;
            }
        }

        /// <summary>
        /// Gets the email address the message originates from.
        /// </summary>
        public EmailAddress SendingAddress
        {
            get
            {
                return _sendingAddress;
            }
        }

        /// <summary>
        /// Gets the time the pose was made.
        /// </summary>
        public DateTime PostTime
        {
            get
            {
                return _postTime;
            }
        }

        /// <summary>
        /// Gets or sets the body of the message.
        /// </summary>
        public string Body
        {
            get
            {
                return _body;
            }
            set
            {
                _body = value;
            }
        }

        /// <summary>
        /// Gets the phone number of the sender.
        /// </summary>
        public PhoneNumber SendingPhoneNumber
        {
            get
            {
                return _sendingTel;
            }
            set
            {
                _sendingTel = value;
            }
        }
    }
}
